﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;

namespace FileModelNS
{
	public class BaseUtility
	{
		public static byte[] ConvertHexValueToByteArray(string value)
		{
			if (!value.StartsWith("0x"))
				throw new NonHexValueException(value);

			int size = (value.Length - 2) / 2;
			byte[] ret = new byte[size];

			for (int i = 0; i < size; i++)
				ret[i] = (byte)int.Parse(value.Substring(i * 2 + 2, 2), NumberStyles.AllowHexSpecifier); ;

			return ret;
		}

		public static bool CompareArray<T>(T[] arr1, T[] arr2)
		{
			if (arr1.Length != arr2.Length) return false;
			int len = (arr1.Length < arr2.Length ? arr1.Length : arr2.Length);

			for (int i = 0; i < len; ++i)
				if ( ! arr1[i].Equals( arr2[i]))
					return false;

			return true;
		}
	}
}
